import Base from 'models/base';

export default class UserPassword extends Base {
  oldPassword = '';
  newPassword = '';
  confirmPassword = '';
  phoneCode = '';
  userPhone = '';

  constructor(user) {
    super();

    this.userPhone = user.userPhone;
  }

  checkValid() {
    let fields = ['oldPassword', 'newPassword', 'confirmPassword', 'phoneCode'];
    let code = this.checkRequired(fields);
    if (code !== '') {
      return code;
    }

    if (this.newPassword !== this.confirmPassword) {
      return 'newPassword!==confirmPassword';
    }

    return '';
  }

  getObject() {
    let postData = {
      lastPassword: this.oldPassword,
      newPassword: this.newPassword,
      phoneCode: this.phoneCode,
      userPhone: this.userPhone
    };

    return postData;
  }
}
